package test1;
import java.lang.reflect.Method;
import javapict.Operations;
import javapict.Channel;

public class InpOutTest{
        private Channel<Integer> ch = new Channel<Integer>("Integer");
        static Operations op = new Operations();
        public void A(){
                ch.var = -1;
                Channel<Integer> y = new Channel<Integer>("Integer");
                y.var = 10;
                op.Send(ch, y);
                System.out.println("Sent "+ch.var);
                int temp = 100;
                for(int i = 0; i < 1000000000; i++){
                        temp = temp *100;
                }
                System.out.println("leaving A");
        }
        public void B(){
                ch.var = -1;
                Channel<Integer> z = new Channel<Integer>("Integer");
                z.var = -1;
                System.out.println("entered B");
                while(op.Receive(ch, z) == false) {
                        long current = System.currentTimeMillis();
                        long future = current+1000;
                        while(System.currentTimeMillis() < future){}
                }
                System.out.println("Received "+z.var);
                System.out.println("leaving B");
        }
        public static void main(String args[]){
                InpOutTest object = new InpOutTest();
                Class cls = object.getClass();
                try {
                        Method proc1 = cls.getMethod("A");
                        Method proc2 = cls.getMethod("B");//, new Class[]{null});
                        op.parallel(proc1, proc2, (Object)object);
                } catch (SecurityException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                } catch (NoSuchMethodException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }               
        }
}